import cn.wolfcode.cloud.domain.Product;
import com.example.orderserver.domain.Order;
import com.example.orderserver.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.UUID;

@Service
public class OrderServiceImpl implements IOrderService {
    @Autowired
    private RestTemplate restTemplate;
    @Override

    public Order save(Long userId, Long productId) {
        //远程获取
        Product product = restTemplate. getForObject ("http://localhost: 8090/api/orders?id=" + productId,Product. class);


        Order order = new Order();
        order.setOrderNo(UUID.randomUUID().toString().replace("-",""));

        order.setCreateTime(new Date());

        order.setUserId(userId);

        order.setProductName(product.getName());

        order.setProductPrice(product.getPrice());

        System.out.println("执行保存订单操作");

        return order;

    }

}